package com.knife.blog.web.servlet;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

//import com.knife.blog.domain.SysConfig;
//import com.knife.dbo.EasyJDB;
import com.knife.blog.logic.SysConfig;
import com.knife.web.ActionContext;
import com.knife.web.ActionServlet;

public class BlogServlet extends ActionServlet {
	
	public void init(ServletConfig config){
		try {
			super.init(config);
			initBlog();
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}

	private void initBlog() {
		// TODO 自动生成方法存根
		/*EasyJDB db = EasyJDB.getInstance();
		SysConfig sysConfig = new SysConfig();
		sysConfig = (SysConfig)db.query(SysConfig.class, "cid='sysconfig'").get(0);
		if(sysConfig==null)
			System.out.println(sysConfig.getSiteName()+sysConfig.getSiteUrl());
		else
			System.out.println(sysConfig.getSiteName()+"        "+sysConfig.getSiteUrl()+"        "+sysConfig.getCid());*/
		/*ResourceBundle bundle = ResourceBundle.getBundle("com.knife.blog.properties.SysConfig");
		Map sysConfig = new HashMap();
		for(Enumeration keys = bundle.getKeys();keys.hasMoreElements();){
			String bundleKey = (String)keys.nextElement();
			System.out.println(bundleKey);
			String key = bundleKey.substring(bundleKey.lastIndexOf(".")+1, bundleKey.length());
			System.out.println(key);
			sysConfig.put(key, bundle.getString(bundleKey));
			System.out.println(bundleKey+":"+bundle.getString(bundleKey));
		}*/
		SysConfig sysConfig = SysConfig.getInstance();
		ServletContext context = this.getServletContext();
		System.out.println(context);
		context.setAttribute("sysConfig", sysConfig);
	}

}
